package com.ds.infrastructure.hyperspace.common.flow;

/**
 * @author  Weishaoying
 */
public interface EntryProtocolAdapter<C extends DuplexFlowContext> {

    /**
     * Close corresponding channel
     */
    void closeEntryChannel();

    /**
     * Get current connection flow context
     * @return
     */
    C currentDuplexFlowContext();

    /**
     * Get flow context
     * @param flowContextKey
     * @return
     */
    C requireDuplexFlowContext(int flowContextKey);

    /**
     * Write data to entry
     * @param duplexFlowContext
     * @param msg
     */
    void writeToEntry(C duplexFlowContext, Object msg);

    /**
     * Flush data to entry
     */
    void flushToEntry();

    /**
     * Write interrupt data to entry
     * @param duplexFlowContext
     */
    void interruptToEntry(C duplexFlowContext);

    /**
     * Get request header
     * @param duplexFlowContext
     * @param headerName
     * @return
     */
    String getEntryHeader(C duplexFlowContext, String headerName);

    /**
     * Get request body bytes
     * @param duplexFlowContext
     * @return
     */
    byte[] getEntryBody(C duplexFlowContext);

    /**
     * Release data
     * @param data
     */
    void releaseData(Object data);

    /**
     * Clear suspend request
     */
    void clearSuspendRequest();

    /**
     * Returns true if the Channel is open
     * @return
     */
    boolean isChannelOpen();

    /**
     * Release duplexFlowContext
     */
    void releaseDuplexFlowContext();
}
